<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id
	
	+ Module  		: m_vendor Controller
	+ Description	: For record controller process back-end
	+ Filename 		: C_m_vendor.php
 	+ creator 		: 
 	+ Created on 24/Jul/2012 11:40:14
	
*/

//class of m_vendor
class C_m_vendor extends CI_Controller {

	//constructor
	function __construct(){
		parent::__construct();
		
		$this->load->model('m_m_vendor', '', TRUE);
		checkLogin();
	}
	
	function get_div(){
		$result=$this->m_m_vendor->get_div();
		echo $result;
	}
	
	//set index
	function index(){
		$this->load->view('main/v_m_vendor');
	}
	
	//event handler action
	function get_action(){
		$task = $_POST['task'];
		switch($task){
			case "LIST":
				$this->m_vendor_list();
				break;
			case "UPDATE":
				$this->m_vendor_update();
				break;
			case "CREATE":
				$this->m_vendor_create();
				break;
			case "DELETE":
				$this->m_vendor_delete();
				break;
			case "SEARCH":
				$this->m_vendor_search();
				break;
			case "PRINT":
				$this->m_vendor_print();
				break;
			case "EXCEL":
				$this->m_vendor_export_excel();
				break;
			default:
				echo "{failure:true}";
				break;
		}
	}
	
	//function fot list record
	function m_vendor_list(){
		
		$query = isset($_POST['query']) ? @$_POST['query'] : "";
		$start = (integer) (isset($_POST['start']) ? @$_POST['start'] : @$_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? @$_POST['limit'] : @$_GET['limit']);
		$result=$this->m_m_vendor->m_vendor_list($query,$start,$end);
		echo $result;
	}
	
	//function for create new record
	function m_vendor_create(){
		//POST varible here
		//auto increment, don't accept anything from form values
		$vendor_kode=trim(@$_POST["vendor_kode"]);
		$vendor_kode=htmlentities($vendor_kode,ENT_QUOTES);
		$vendor_name=trim(@$_POST["vendor_name"]);
		$vendor_name=htmlentities($vendor_name,ENT_QUOTES);
		$vendor_type=trim(@$_POST["vendor_type"]);
		$vendor_type=htmlentities($vendor_type,ENT_QUOTES);
		$vendor_address=trim(@$_POST["vendor_address"]);
		$vendor_address=htmlentities($vendor_address,ENT_QUOTES);
		$vendor_phone=trim(@$_POST["vendor_phone"]);
		$vendor_phone=htmlentities($vendor_phone,ENT_QUOTES);
		$vendor_fax=trim(@$_POST["vendor_fax"]);
		$vendor_fax=htmlentities($vendor_fax,ENT_QUOTES);
		$vendor_email=trim(@$_POST["vendor_email"]);
		$vendor_email=htmlentities($vendor_email,ENT_QUOTES);
		$vendor_cp=trim(@$_POST["vendor_cp"]);
		$vendor_cp=htmlentities($vendor_cp,ENT_QUOTES);
		$vendor_dir=trim(@$_POST["vendor_dir"]);
		$vendor_dir=htmlentities($vendor_dir,ENT_QUOTES);
		$vendor_dirpos=trim(@$_POST["vendor_dirpos"]);
		$vendor_dirpos=htmlentities($vendor_dirpos,ENT_QUOTES);
		$vendor_rek=trim(@$_POST["vendor_rek"]);
		$vendor_rek=htmlentities($vendor_rek,ENT_QUOTES);
		$vendor_bank=trim(@$_POST["vendor_bank"]);
		$vendor_bank=htmlentities($vendor_bank,ENT_QUOTES);
		$vendor_bankowner=trim(@$_POST["vendor_bankowner"]);
		$vendor_bankowner=htmlentities($vendor_bankowner,ENT_QUOTES);
		$vendor_cert=trim(@$_POST["vendor_cert"]);
		$vendor_cert=htmlentities($vendor_cert,ENT_QUOTES);
		$vendor_npwp=trim(@$_POST["vendor_npwp"]);
		$vendor_npwp=htmlentities($vendor_npwp,ENT_QUOTES);
		$vendor_certdate=trim(@$_POST["vendor_certdate"]);
		$vendor_active=trim(@$_POST["vendor_active"]);
		$vendor_active=htmlentities($vendor_active,ENT_QUOTES);
		$vendor_created_date=trim(@$_POST["vendor_created_date"]);
		$vendor_created_by=trim(@$_POST["vendor_created_by"]);
		$vendor_created_by=htmlentities($vendor_created_by,ENT_QUOTES);
		$vendor_updated_date=trim(@$_POST["vendor_updated_date"]);
		$vendor_updated_by=trim(@$_POST["vendor_updated_by"]);
		$vendor_updated_by=htmlentities($vendor_updated_by,ENT_QUOTES);
		$vendor_updated_count=@$_POST["vendor_updated_count"];
		$vendor_updated_count=is_numeric($vendor_updated_count)?$vendor_updated_count:0;
		$m_div_id=@$_POST["m_div_id"];
		$result=$this->m_m_vendor->m_vendor_create($vendor_kode ,$vendor_name ,$vendor_type ,$vendor_address ,$vendor_phone ,$vendor_fax ,$vendor_email ,$vendor_cp ,$vendor_dir ,$vendor_dirpos ,$vendor_rek ,$vendor_bank ,$vendor_bankowner ,$vendor_cert ,$vendor_certdate ,$vendor_active ,$vendor_created_date ,$vendor_created_by ,$vendor_updated_date ,$vendor_updated_by ,$vendor_updated_count ,$m_div_id,$vendor_npwp );
		echo $result;
	}
	
	
	//function for update record
	function m_vendor_update(){
		//POST variable here
		$vendor_id=@$_POST["vendor_id"];
		$vendor_id=is_numeric($vendor_id)?$vendor_id:0;
		$vendor_kode=trim(@$_POST["vendor_kode"]);
		$vendor_kode=htmlentities($vendor_kode,ENT_QUOTES);
		$vendor_name=trim(@$_POST["vendor_name"]);
		$vendor_name=htmlentities($vendor_name,ENT_QUOTES);
		$vendor_type=trim(@$_POST["vendor_type"]);
		$vendor_type=htmlentities($vendor_type,ENT_QUOTES);
		$vendor_address=trim(@$_POST["vendor_address"]);
		$vendor_address=htmlentities($vendor_address,ENT_QUOTES);
		$vendor_phone=trim(@$_POST["vendor_phone"]);
		$vendor_phone=htmlentities($vendor_phone,ENT_QUOTES);
		$vendor_fax=trim(@$_POST["vendor_fax"]);
		$vendor_fax=htmlentities($vendor_fax,ENT_QUOTES);
		$vendor_email=trim(@$_POST["vendor_email"]);
		$vendor_email=htmlentities($vendor_email,ENT_QUOTES);
		$vendor_cp=trim(@$_POST["vendor_cp"]);
		$vendor_cp=htmlentities($vendor_cp,ENT_QUOTES);
		$vendor_dir=trim(@$_POST["vendor_dir"]);
		$vendor_dir=htmlentities($vendor_dir,ENT_QUOTES);
		$vendor_dirpos=trim(@$_POST["vendor_dirpos"]);
		$vendor_dirpos=htmlentities($vendor_dirpos,ENT_QUOTES);
		$vendor_rek=trim(@$_POST["vendor_rek"]);
		$vendor_rek=htmlentities($vendor_rek,ENT_QUOTES);
		$vendor_bank=trim(@$_POST["vendor_bank"]);
		$vendor_bank=htmlentities($vendor_bank,ENT_QUOTES);
		$vendor_bankowner=trim(@$_POST["vendor_bankowner"]);
		$vendor_bankowner=htmlentities($vendor_bankowner,ENT_QUOTES);
		$vendor_cert=trim(@$_POST["vendor_cert"]);
		$vendor_cert=htmlentities($vendor_cert,ENT_QUOTES);
		$vendor_npwp=trim(@$_POST["vendor_npwp"]);
		$vendor_npwp=htmlentities($vendor_npwp,ENT_QUOTES);
		$vendor_certdate=trim(@$_POST["vendor_certdate"]);
		$vendor_active=trim(@$_POST["vendor_active"]);
		$vendor_active=htmlentities($vendor_active,ENT_QUOTES);
		$vendor_created_date=trim(@$_POST["vendor_created_date"]);
		$vendor_created_by=trim(@$_POST["vendor_created_by"]);
		$vendor_created_by=htmlentities($vendor_created_by,ENT_QUOTES);
		$vendor_updated_date=trim(@$_POST["vendor_updated_date"]);
		$vendor_updated_by=trim(@$_POST["vendor_updated_by"]);
		$vendor_updated_by=htmlentities($vendor_updated_by,ENT_QUOTES);
		$vendor_updated_count=@$_POST["vendor_updated_count"];
		$vendor_updated_count=is_numeric($vendor_updated_count)?$vendor_updated_count:0;
		$m_div_id=@$_POST["m_div_id"];
		$result = $this->m_m_vendor->m_vendor_update($vendor_id,$vendor_kode,$vendor_name,$vendor_type,$vendor_address,$vendor_phone,$vendor_fax,$vendor_email,$vendor_cp,$vendor_dir,$vendor_dirpos,$vendor_rek,$vendor_bank,$vendor_bankowner,$vendor_cert,$vendor_certdate,$vendor_active,$vendor_created_date,$vendor_created_by,$vendor_updated_date,$vendor_updated_by,$vendor_updated_count,$m_div_id,$vendor_npwp);
		echo $result;
	}
	
	//function for delete selected record
	function m_vendor_delete(){
		$ids = @$_POST['ids']; // Get our array back and translate it :
		$pkid = json_decode(stripslashes($ids));
		$result=$this->m_m_vendor->m_vendor_delete($pkid);
		echo $result;
	}

	//function for advanced search
	function m_vendor_search(){
		//POST varibale here
		$vendor_id=@$_POST["vendor_id"];
		$vendor_id=is_numeric($vendor_id)?$vendor_id:0;
		$vendor_name=trim(@$_POST["vendor_name"]);
		$vendor_name=htmlentities($vendor_name,ENT_QUOTES);
		$vendor_type=trim(@$_POST["vendor_type"]);
		$vendor_type=htmlentities($vendor_type,ENT_QUOTES);
		$vendor_address=trim(@$_POST["vendor_address"]);
		$vendor_address=htmlentities($vendor_address,ENT_QUOTES);
		$vendor_phone=trim(@$_POST["vendor_phone"]);
		$vendor_phone=htmlentities($vendor_phone,ENT_QUOTES);
		$vendor_fax=trim(@$_POST["vendor_fax"]);
		$vendor_fax=htmlentities($vendor_fax,ENT_QUOTES);
		$vendor_email=trim(@$_POST["vendor_email"]);
		$vendor_email=htmlentities($vendor_email,ENT_QUOTES);
		$vendor_cp=trim(@$_POST["vendor_cp"]);
		$vendor_cp=htmlentities($vendor_cp,ENT_QUOTES);
		$vendor_dir=trim(@$_POST["vendor_dir"]);
		$vendor_dir=htmlentities($vendor_dir,ENT_QUOTES);
		$vendor_dirpos=trim(@$_POST["vendor_dirpos"]);
		$vendor_dirpos=htmlentities($vendor_dirpos,ENT_QUOTES);
		$vendor_rek=trim(@$_POST["vendor_rek"]);
		$vendor_rek=htmlentities($vendor_rek,ENT_QUOTES);
		$vendor_bank=trim(@$_POST["vendor_bank"]);
		$vendor_bank=htmlentities($vendor_bank,ENT_QUOTES);
		$vendor_bankowner=trim(@$_POST["vendor_bankowner"]);
		$vendor_bankowner=htmlentities($vendor_bankowner,ENT_QUOTES);
		$vendor_cert=trim(@$_POST["vendor_cert"]);
		$vendor_cert=htmlentities($vendor_cert,ENT_QUOTES);
		$vendor_certdate=trim(@$_POST["vendor_certdate"]);
		$vendor_active=trim(@$_POST["vendor_active"]);
		$vendor_active=htmlentities($vendor_active,ENT_QUOTES);
		$vendor_created_date=trim(@$_POST["vendor_created_date"]);
		$vendor_created_by=trim(@$_POST["vendor_created_by"]);
		$vendor_created_by=htmlentities($vendor_created_by,ENT_QUOTES);
		$vendor_updated_date=trim(@$_POST["vendor_updated_date"]);
		$vendor_updated_by=trim(@$_POST["vendor_updated_by"]);
		$vendor_updated_by=htmlentities($vendor_updated_by,ENT_QUOTES);
		$vendor_updated_count=@$_POST["vendor_updated_count"];
		$vendor_updated_count=is_numeric($vendor_updated_count)?$vendor_updated_count:0;
		$m_div_id=@$_POST["m_div_id"];
		$m_div_id=is_numeric($m_div_id)?$m_div_id:0;
		
		$start = (integer) (isset($_POST['start']) ? $_POST['start'] : $_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']);
		$result = $this->m_m_vendor->m_vendor_search($vendor_id ,$vendor_name ,$vendor_type ,$vendor_address ,$vendor_phone ,$vendor_fax ,$vendor_email ,$vendor_cp ,$vendor_dir ,$vendor_dirpos ,$vendor_rek ,$vendor_bank ,$vendor_bankowner ,$vendor_cert ,$vendor_certdate ,$vendor_active ,$vendor_created_date ,$vendor_created_by ,$vendor_updated_date ,$vendor_updated_by ,$vendor_updated_count ,$m_div_id ,$start,$end);
		echo $result;
	}


	function m_vendor_print(){
  		//POST varibale here
		$vendor_id=@$_POST["vendor_id"];
		$vendor_id=is_numeric($vendor_id)?$vendor_id:0;
		$vendor_name=trim(@$_POST["vendor_name"]);
		$vendor_name=htmlentities($vendor_name,ENT_QUOTES);
		$vendor_type=trim(@$_POST["vendor_type"]);
		$vendor_type=htmlentities($vendor_type,ENT_QUOTES);
		$vendor_address=trim(@$_POST["vendor_address"]);
		$vendor_address=htmlentities($vendor_address,ENT_QUOTES);
		$vendor_phone=trim(@$_POST["vendor_phone"]);
		$vendor_phone=htmlentities($vendor_phone,ENT_QUOTES);
		$vendor_fax=trim(@$_POST["vendor_fax"]);
		$vendor_fax=htmlentities($vendor_fax,ENT_QUOTES);
		$vendor_email=trim(@$_POST["vendor_email"]);
		$vendor_email=htmlentities($vendor_email,ENT_QUOTES);
		$vendor_cp=trim(@$_POST["vendor_cp"]);
		$vendor_cp=htmlentities($vendor_cp,ENT_QUOTES);
		$vendor_dir=trim(@$_POST["vendor_dir"]);
		$vendor_dir=htmlentities($vendor_dir,ENT_QUOTES);
		$vendor_dirpos=trim(@$_POST["vendor_dirpos"]);
		$vendor_dirpos=htmlentities($vendor_dirpos,ENT_QUOTES);
		$vendor_rek=trim(@$_POST["vendor_rek"]);
		$vendor_rek=htmlentities($vendor_rek,ENT_QUOTES);
		$vendor_bank=trim(@$_POST["vendor_bank"]);
		$vendor_bank=htmlentities($vendor_bank,ENT_QUOTES);
		$vendor_bankowner=trim(@$_POST["vendor_bankowner"]);
		$vendor_bankowner=htmlentities($vendor_bankowner,ENT_QUOTES);
		$vendor_cert=trim(@$_POST["vendor_cert"]);
		$vendor_cert=htmlentities($vendor_cert,ENT_QUOTES);
		$vendor_certdate=trim(@$_POST["vendor_certdate"]);
		$vendor_active=trim(@$_POST["vendor_active"]);
		$vendor_active=htmlentities($vendor_active,ENT_QUOTES);
		$vendor_created_date=trim(@$_POST["vendor_created_date"]);
		$vendor_created_by=trim(@$_POST["vendor_created_by"]);
		$vendor_created_by=htmlentities($vendor_created_by,ENT_QUOTES);
		$vendor_updated_date=trim(@$_POST["vendor_updated_date"]);
		$vendor_updated_by=trim(@$_POST["vendor_updated_by"]);
		$vendor_updated_by=htmlentities($vendor_updated_by,ENT_QUOTES);
		$vendor_updated_count=@$_POST["vendor_updated_count"];
		$vendor_updated_count=is_numeric($vendor_updated_count)?$vendor_updated_count:0;
		$m_div_id=@$_POST["m_div_id"];
		$m_div_id=is_numeric($m_div_id)?$m_div_id:0;
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		
		$data["data_print"] = $this->m_m_vendor->m_vendor_print($vendor_id ,$vendor_name ,$vendor_type ,$vendor_address ,$vendor_phone ,$vendor_fax ,$vendor_email ,$vendor_cp ,$vendor_dir ,$vendor_dirpos ,$vendor_rek ,$vendor_bank ,$vendor_bankowner ,$vendor_cert ,$vendor_certdate ,$vendor_active ,$vendor_created_date ,$vendor_created_by ,$vendor_updated_date ,$vendor_updated_by ,$vendor_updated_count ,$m_div_id ,$option,$filter);
		$print_view=$this->load->view("main/p_m_vendor.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/m_vendor_printlist.html","w+");
		fwrite($print_file, $print_view);
		echo '1';        
	}
	/* End Of Function */

	/* Function to Export Excel document */
	function m_vendor_export_excel(){
		//POST varibale here
		$vendor_id=@$_POST["vendor_id"];
		$vendor_id=is_numeric($vendor_id)?$vendor_id:0;
		$vendor_name=trim(@$_POST["vendor_name"]);
		$vendor_name=htmlentities($vendor_name,ENT_QUOTES);
		$vendor_type=trim(@$_POST["vendor_type"]);
		$vendor_type=htmlentities($vendor_type,ENT_QUOTES);
		$vendor_address=trim(@$_POST["vendor_address"]);
		$vendor_address=htmlentities($vendor_address,ENT_QUOTES);
		$vendor_phone=trim(@$_POST["vendor_phone"]);
		$vendor_phone=htmlentities($vendor_phone,ENT_QUOTES);
		$vendor_fax=trim(@$_POST["vendor_fax"]);
		$vendor_fax=htmlentities($vendor_fax,ENT_QUOTES);
		$vendor_email=trim(@$_POST["vendor_email"]);
		$vendor_email=htmlentities($vendor_email,ENT_QUOTES);
		$vendor_cp=trim(@$_POST["vendor_cp"]);
		$vendor_cp=htmlentities($vendor_cp,ENT_QUOTES);
		$vendor_dir=trim(@$_POST["vendor_dir"]);
		$vendor_dir=htmlentities($vendor_dir,ENT_QUOTES);
		$vendor_dirpos=trim(@$_POST["vendor_dirpos"]);
		$vendor_dirpos=htmlentities($vendor_dirpos,ENT_QUOTES);
		$vendor_rek=trim(@$_POST["vendor_rek"]);
		$vendor_rek=htmlentities($vendor_rek,ENT_QUOTES);
		$vendor_bank=trim(@$_POST["vendor_bank"]);
		$vendor_bank=htmlentities($vendor_bank,ENT_QUOTES);
		$vendor_bankowner=trim(@$_POST["vendor_bankowner"]);
		$vendor_bankowner=htmlentities($vendor_bankowner,ENT_QUOTES);
		$vendor_cert=trim(@$_POST["vendor_cert"]);
		$vendor_cert=htmlentities($vendor_cert,ENT_QUOTES);
		$vendor_certdate=trim(@$_POST["vendor_certdate"]);
		$vendor_active=trim(@$_POST["vendor_active"]);
		$vendor_active=htmlentities($vendor_active,ENT_QUOTES);
		$vendor_created_date=trim(@$_POST["vendor_created_date"]);
		$vendor_created_by=trim(@$_POST["vendor_created_by"]);
		$vendor_created_by=htmlentities($vendor_created_by,ENT_QUOTES);
		$vendor_updated_date=trim(@$_POST["vendor_updated_date"]);
		$vendor_updated_by=trim(@$_POST["vendor_updated_by"]);
		$vendor_updated_by=htmlentities($vendor_updated_by,ENT_QUOTES);
		$vendor_updated_count=@$_POST["vendor_updated_count"];
		$vendor_updated_count=is_numeric($vendor_updated_count)?$vendor_updated_count:0;
		$m_div_id=@$_POST["m_div_id"];
		$m_div_id=is_numeric($m_div_id)?$m_div_id:0;
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		$data["type"]="excel";
		$data["data_print"] = $this->m_m_vendor->m_vendor_print($vendor_id ,$vendor_name ,$vendor_type ,$vendor_address ,$vendor_phone ,$vendor_fax ,$vendor_email ,$vendor_cp ,$vendor_dir ,$vendor_dirpos ,$vendor_rek ,$vendor_bank ,$vendor_bankowner ,$vendor_cert ,$vendor_certdate ,$vendor_active ,$vendor_created_date ,$vendor_created_by ,$vendor_updated_date ,$vendor_updated_by ,$vendor_updated_count ,$m_div_id ,$option,$filter);
		$print_view=$this->load->view("main/p_m_vendor.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/m_vendor_printlist.xls","w+");
		fwrite($print_file, $print_view);
		echo '1';   
			
	}
	
	// Encodes a SQL array into a JSON formated string
	function JEncode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->encode($arr);  //encode the data in json format
		} else {
			$data = json_encode($arr);  //encode the data in json format
		}
		return $data;
	}
	
	// Decode a SQL array into a JSON formated string
	function JDecode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->decode($arr);  //decode the data in json format
		} else {
			$data = json_decode($arr);  //decode the data in json format
		}
		return $data;
	}
		
}
?>